package com.steak.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * @author 刘牌
 * @Title:
 * @date 2022-04-1523:20
 */
public class Test {
    public static void main(String[] args) throws InterruptedException {
        //四个线程，A线程打印A，B线程打印B，C线程打印C，D线程打印D，要求按顺序打印ABCD，键盘输入打印的次数

        final int printCount = 8;
        final CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 0; i < printCount; i++) {
            Thread a = new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+":  "+"A");
            }, "Thread-A");

            Thread b = new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+":  "+"B");
            }, "Thread-B");

            Thread c = new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+":  "+"C");
            }, "Thread-C");

            Thread d = new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+":  "+"D");
            }, "Thread-D");

            a.start();
            b.join();
            c.join();
            d.join();

            b.start();
            c.join();
            d.join();
            a.join();

            c.start();
            d.join();
            a.join();
            b.join();

            d.start();
            c.join();
            b.join();
            a.join();

        }
    }
}
